from interface.Memberiniterce1 import MemberInterface
from utile.sendmethod import SendMethod
# 确认订单
# 生成订单
# 支付
class OrderInterface:
    def __init__(self, url, headers):
        self.url = url
        self.headers = headers

    # 确认订单
    def confirm_order(self, payload):
        method = 'post'
        url = self.url + '/order/generateConfirmOrder'
        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    # 生成订单
    def generate_orber(self, pramas):
        method = 'post'
        url = self.url + '/order/generateOrder'
        # pramas = {
        #     "cartIds": [
        #         2755
        #     ],
        #     "memberReceiveAddressId": 2507,  # 收货地址id
        #     "payType": 2,  # 支付方式,0: 未支付;1: 支付宝,;2: 微信
        # }
        return SendMethod.send_method(method=method, url=url, json=pramas, headers=self.headers)

    # 支付
    def pay_success(self,payload):
        method = 'post'
        url = self.url + '/order/paySuccess'
        return SendMethod.send_method(method=method, url=url, data=payload, headers=self.headers)


if __name__ == '__main__':
    url = 'http://47.108.206.100:8085'
    headers = MemberInterface(url).get_token('ymYM', 654321)
    ob = OrderInterface(url, headers)
    # print(ob.confirm_order([2755]))  #确认订单
    params={
        "cartIds": [
            2755
        ],
        "memberReceiveAddressId": 2508,
        "payType": 0,
    }
    # print(ob.generate_orber(params))  #生成订单
    payload = {'orderId': 3627, 'payType': 0}
    print(ob.pay_success(payload))     #支付
